import { injectable, inject } from "inversify";
import { PrismaDB } from "../../db";
import { MessageDto } from "./message.dto";

@injectable()
export class MessageService {
  // 自动注入prisma
  constructor(@inject(PrismaDB) private PrismaDB: PrismaDB) {}

  /**
   * 添加消息
   */
  public async send(message: MessageDto) {
    return await this.PrismaDB.prisma.message.create({
      data: {
        text: message.text,
        userId: message.userId,
        userName: message.userName,
      },
    });
  }

  /**
   * 获取消息列表
   */
  public async list() {
    return await this.PrismaDB.prisma.message.findMany();
  }
}
